//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ProvenanceCommon.Model
{
    using Microsoft.Research.ScientificWorkflow.UIDesigner.Monitor;
    using SR = Microsoft.Research.DataLayer;
    using System.Globalization;

    /// <summary>
    /// Contains model for provenance's activity outputs.
    /// </summary>
    public class ActivityProperty
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="propertyData">InputOutput</param>
        public ActivityProperty(SR.InputOutput propertyData)
        {
            this.Name = propertyData.PropertyName;
            this.Value = propertyData.PropertyValue;
            this.ActivityName = propertyData.Provenance.ProvenanceInfo.ActivityName;
        }

        /// <summary>
        /// Empty Constructor
        /// </summary>
        public ActivityProperty()
        {
        }

        /// <summary>
        /// Gets or sets the parameter name.
        /// </summary>
        /// <value>The name.</value>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the paremeter value.
        /// </summary>
        /// <value>The value.</value>
        public string Value { get; set; }

        /// <summary>
        /// Gets or sets the direction.
        /// </summary>
        /// <value>The direction.</value>
        public SR.DirectionType Direction { get; set; }

        /// <summary>
        /// Gets or sets the name of the activity.
        /// </summary>
        /// <value>The name of the activity.</value>
        public string ActivityName { get; set; }

        /// <summary>
        /// Gets or sets the Actual data product Item.
        /// </summary>
        /// <value>The data.</value>
        public DataProductItem Data { get; set; }


        /// <summary>
        /// EventOrder of the InputOutput
        /// </summary>
        public System.Int32 EventOrder { get; set; }

        /// <summary>
        /// Gets or sets the name of the dataproduct.
        /// </summary>
        /// <value>The name of the dataproduct.</value>
        public string DataProductName
        {
            get
            {
                if (this.Data != null)
                {
                    return this.Data.Name;
                }
                else
                {
                    return string.Empty;
                }
            }
        }

        /// <summary>
        /// Gets the display name.
        /// </summary>
        /// <value>The display name.</value>
        public string DisplayName
        {
            get
            {
                if (!string.IsNullOrEmpty(this.Name) && !string.IsNullOrEmpty(this.ActivityName))
                {
                    return string.Format(CultureInfo.CurrentCulture, "{0}.{1}", this.ActivityName, this.Name);
                }
                else
                {
                    return string.Empty;
                }
            }
        }

        /// <summary>
        /// Overridden tostring method. For automation Ids.
        /// </summary>
        /// <returns>The string representation of the object.</returns>
        public override string ToString()
        {
            if (!string.IsNullOrEmpty(this.Name) && !string.IsNullOrEmpty(this.ActivityName))
            {
                return string.Format(CultureInfo.CurrentCulture, "{0}.{1}", this.ActivityName, this.Name);
            }
            return base.ToString();
        }
    }
}
